#!/bin/bash

mkdir -p ./volume/vaultwarden/data
mkdir -p ./volume/nginx/{conf.d,log,wwwroot}

echo '开放端口'
# # nginx
# firewall-cmd --zone=public --add-port=9980/tcp --permanent
# firewall-cmd --zone=public --add-port=9443/tcp --permanent
# 定义需要开放的端口列表
PORTS=("9980/tcp" "9443/tcp")

for port in "${PORTS[@]}"; do
    # 检查端口是否已开放
    if ! firewall-cmd --query-port="$port" >/dev/null 2>&1; then
        # 未开放则执行开放命令
        echo "开放端口 $port"
        firewall-cmd --add-port="$port" --permanent
    else
        echo "端口 $port 已开放，跳过"
    fi
done
firewall-cmd --reload

# 生成token
# docker run --rm -it vaultwarden/server:1.29.1 /vaultwarden hash
# echo -n "MySecretPassword" | argon2 "$(openssl rand -base64 32)" -e -id -k 65540 -t 3 -p 4

echo '启动容器'
docker-compose up -d

echo '查看容器'
docker-compose ps
